home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / shell / igo / gosource / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  13.0 KB  |  492 lines

  1. #define DEBUG 0
  2. /* 
  3.     TOWNS囲碁棋譜記録プログラム
  4.                                           1991/12/11  久保田俊也
  5.  
  6.     91/12/11  display モジュールを本体より分離 
  7.  
  8.  
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <winb.h>
  14. #include <egb.h>
  15. #include <te.h>
  16. #include <fntb.h>
  17. #include <gui.h>
  18. #include "igo.h"
  19. #include "banx.h"
  20. #include "kiffile.h"
  21. #include "title.h"
  22.  
  23. #define BANX 0
  24. #define BANY 0
  25. #define ISHI_R 11
  26. #define BANX2 BANX + 20*ISHI_R*2
  27. #define BANY2 BANY + 20*ISHI_R*2
  28.  
  29. static int banx1, bany1, banx2, bany2, ishi_r, ishi_2r, x_len;
  30. static int type, bansize;
  31. static char save_ban[MAX_BANSIZE2];
  32. extern char *guiEgbPtr;
  33. char *gwork;    /* グラフイックBIOSワーク */
  34. char para[64] ;
  35. int ban_color, line_color;
  36.  
  37. int disp_init()
  38. {
  39. BAN_TYPE ban_type;
  40.  
  41.     ban_type = *title_bantype_read();
  42.     if( ban_type.type == NORMAL){
  43.         type = NORMAL;
  44.         bansize = ban_type.size;
  45.     }
  46.  
  47.     banx1 = BANX;
  48.     bany1 = BANY;
  49.     ishi_r = ISHI_R;
  50.     ishi_2r = ishi_r * 2;
  51.     x_len = ISHI_R - 2;
  52.     banx2 = banx1 + (bansize+1)*ishi_2r;
  53.     bany2 = bany1 + (bansize+1)*ishi_2r;
  54.  
  55.     ban_color = 6;    /* 黄色 */
  56.     line_color = 1; /* 青色 */
  57.     
  58.     gwork = guiEgbPtr;
  59.  
  60.     EGB_writePage( gwork, 0) ;    /* ページ 0     に */
  61.  
  62.     disp_goban();
  63.     ban_init(save_ban);
  64.  
  65.     return 0;
  66. }
  67.  
  68. static int disp_goban()
  69. {
  70. int i, j ;    
  71. int ichi;
  72.  
  73.     MG_mosDisp( 2 ) ;        /* マウスを表示    シナイ */
  74.     
  75.     EGB_color( gwork, 0, 5) ;
  76.     EGB_color( gwork, 2, 5) ;
  77.     EGB_paintMode( gwork, 0x022 ); 
  78.     WGB_box( gwork, BANX, BANY, BANX2, BANY2);     /* [46] 四角を描く */
  79.  
  80.     EGB_color( gwork, 0, ban_color) ;    /* 色を黄(6)にして */
  81.     EGB_color( gwork, 2, ban_color) ;    /* 色を黄(6)にして */
  82.     EGB_paintMode( gwork, 0x022 ); 
  83.     WGB_box( gwork, banx1, bany1, banx2, bany2);     /* [46] 四角を描く */
  84.  
  85.     EGB_color( gwork, 0, line_color) ;
  86.     EGB_color( gwork, 2, line_color) ;
  87.     for ( i = 0; i < bansize; i++){
  88.         WGB_singleLine( gwork, (i+1)*ishi_2r+banx1, bany1+ishi_2r, 
  89.                                (i+1)*ishi_2r+banx1, bany2-ishi_2r) ; 
  90.         WGB_singleLine( gwork, banx1+ishi_2r, bany1+(i+1)*ishi_2r,
  91.                                banx2-ishi_2r, bany1+(i+1)*ishi_2r) ; 
  92.     }
  93.  
  94.     if( type==NORMAL && bansize == 19){
  95.         for ( i = 0; i < 3; i++){
  96.             for ( j = 0; j < 3; j++){
  97.                 WORD(para + 0) = 6*ishi_2r*i+banx1+4*ishi_2r;
  98.                 WORD(para + 2) = 6*ishi_2r*j+bany1+4*ishi_2r;
  99.                 WORD(para + 4) = 2;
  100.                 WGB_circle( gwork, para ) ;  /* その位置に点を描く */
  101.             }
  102.         }
  103.     }
  104.  
  105. /*  盤の回転等を表すために黒丸白丸を表示する */
  106.     ichi = henkan_disp_in( 1, 1);
  107.     EGB_color( gwork, 0, BLACK_COL ) ; 
  108.     EGB_color( gwork, 2, BLACK_COL);
  109.     
  110.     if((ichi % (bansize+1)) == 1){
  111.         WORD(para + 0) = banx1+5;
  112.     }else{
  113.         WORD(para + 0) = banx2-5;
  114.     }
  115.     
  116.     if((ichi / (bansize+1)) == 1){
  117.         WORD(para + 2) = bany1+5;
  118.     }else{
  119.         WORD(para + 2) = bany2-5;
  120.     }
  121.     
  122.     WORD(para + 4) = 3;
  123.     WGB_circle( gwork, para ) ;  /* その位置に点を描く */
  124.  
  125.     ichi = henkan_disp_in( bansize, 1);
  126.     EGB_color( gwork, 0, WHITE_COL ) ; 
  127.     EGB_color( gwork, 2, WHITE_COL);
  128.     
  129.     if((ichi % (bansize+1)) == 1){
  130.         WORD(para + 0) = banx1+5;
  131.     }else{
  132.         WORD(para + 0) = banx2-5;
  133.     }
  134.     
  135.     if((ichi / (bansize+1)) == 1){
  136.         WORD(para + 2) = bany1+5;
  137.     }else{
  138.         WORD(para + 2) = bany2-5;
  139.     }
  140.     
  141.     WORD(para + 4) = 3;
  142.     WGB_circle( gwork, para ) ;  /* その位置に点を描く */
  143.  
  144.      MG_mosDisp( 3 ) ;        /* マウスを表示する */
  145.  
  146.     return 0;
  147. }
  148.  
  149. int disp_te(char ban[],int ex_ban[])
  150. {
  151. char s[4];
  152. int stonex, stoney;
  153. int ichi;
  154. static int save_ex_ban[MAX_BANSIZE2];
  155.  
  156.     MG_mosDisp( 2 ) ;        /* マウスを表示    シナイ */
  157.     EGB_paintMode( gwork, 0x022 );  /*  設定しないといけない? */
  158.  
  159.     for(stoney=1;stoney<(bansize+1);stoney++){
  160.         for(stonex=1;stonex<(bansize+1);stonex++){
  161.             ichi = henkan_disp_out( stonex, stoney);
  162.             if( ban[ichi] != save_ban[stonex + stoney*(bansize+1)] ||
  163.                 ex_ban[ichi] != save_ex_ban[stonex + stoney*(bansize+1)]){
  164.  
  165.                 switch(ban[ichi]){
  166.                 case BLACK:
  167.                     EGB_color( gwork, 0, 1); 
  168.                     EGB_color( gwork, 2, BLACK_COL);
  169.                     gcircle((stonex)*ishi_2r+banx1, (stoney)*ishi_2r+bany1, 
  170.                             ishi_r);
  171.                     break; 
  172.                 case WHITE:
  173.                     EGB_color( gwork, 0, 1 ) ; 
  174.                     EGB_color( gwork, 2, WHITE_COL);
  175.                     gcircle((stonex)*ishi_2r+banx1, (stoney)*ishi_2r+bany1, 
  176.                             ishi_r);
  177.                     break; 
  178.                 case BLANK:
  179.                     disp_te_clear(stonex, stoney);
  180.                     break;
  181.                 case BLACK_CAPTURE:
  182.                     disp_te_clear(stonex, stoney);
  183.                     EGB_color( gwork, 0, 1); 
  184.                     EGB_color( gwork, 2, BLACK_COL);
  185.                     gcircle((stonex)*ishi_2r+banx1, (stoney)*ishi_2r+bany1, 
  186.                             ishi_r);
  187.                     EGB_color( gwork, 0, WHITE_COL); 
  188.                     EGB_color( gwork, 2, WHITE_COL);
  189.                     WGB_singleLine( gwork,
  190.                                     (stonex)*ishi_2r-x_len+banx1,
  191.                                     (stoney)*ishi_2r-x_len+bany1, 
  192.                                     (stonex)*ishi_2r+x_len+banx1,
  193.                                     (stoney)*ishi_2r+x_len+bany1) ; 
  194.                     WGB_singleLine( gwork,
  195.                                     (stonex)*ishi_2r-x_len+banx1,
  196.                                     (stoney)*ishi_2r+x_len+bany1, 
  197.                                     (stonex)*ishi_2r+x_len+banx1,
  198.                                     (stoney)*ishi_2r-x_len+bany1) ; 
  199.                     break; 
  200.                 case WHITE_CAPTURE:
  201.                     disp_te_clear(stonex, stoney);
  202.                     EGB_color( gwork, 0, 1); 
  203.                     EGB_color( gwork, 2, WHITE_COL);
  204.                     gcircle((stonex)*ishi_2r+banx1, (stoney)*ishi_2r+bany1, 
  205.                             ishi_r);
  206.                     EGB_color( gwork, 0, BLACK_COL); 
  207.                     EGB_color( gwork, 2, BLACK_COL);
  208.                     WGB_singleLine( gwork,
  209.                                     (stonex)*ishi_2r-x_len+banx1,
  210.                                     (stoney)*ishi_2r-x_len+bany1, 
  211.                                     (stonex)*ishi_2r+x_len+banx1,
  212.                                     (stoney)*ishi_2r+x_len+bany1) ; 
  213.                     WGB_singleLine( gwork,
  214.                                     (stonex)*ishi_2r-x_len+banx1,
  215.                                     (stoney)*ishi_2r+x_len+bany1, 
  216.                                     (stonex)*ishi_2r+x_len+banx1,
  217.                                     (stoney)*ishi_2r-x_len+bany1) ; 
  218.                     break; 
  219.                 case WALL_TERRITORY:
  220.                     EGB_color( gwork, 0, 1 ) ; 
  221.                     EGB_color( gwork, 2, GREY_COL);
  222.                     gcircle((stonex)*ishi_2r+banx1, (stoney)*ishi_2r+bany1, 
  223.                             ishi_r);
  224.                     break; 
  225.                 case BLACK_TERRITORY:
  226.                     disp_te_clear(stonex, stoney);
  227.                     EGB_color( gwork, 0, BLACK_COL); 
  228.                     EGB_color( gwork, 2, BLACK_COL);
  229.                     WGB_singleLine( gwork,
  230.                                     (stonex)*ishi_2r-x_len+banx1,
  231.                                     (stoney)*ishi_2r-x_len+bany1, 
  232.                                     (stonex)*ishi_2r+x_len+banx1,
  233.                                     (stoney)*ishi_2r+x_len+bany1) ; 
  234.                     WGB_singleLine( gwork,
  235.                                     (stonex)*ishi_2r-x_len+banx1,
  236.                                     (stoney)*ishi_2r+x_len+bany1, 
  237.                                     (stonex)*ishi_2r+x_len+banx1,
  238.                                     (stoney)*ishi_2r-x_len+bany1) ; 
  239.                     break;
  240.                 case WHITE_TERRITORY:
  241.                     disp_te_clear(stonex, stoney);
  242.                     EGB_color( gwork, 0, WHITE_COL); 
  243.                     EGB_color( gwork, 2, WHITE_COL);
  244.                     WGB_singleLine( gwork,
  245.                                     (stonex)*ishi_2r-x_len+banx1,
  246.                                     (stoney)*ishi_2r-x_len+bany1, 
  247.                                     (stonex)*ishi_2r+x_len+banx1,
  248.                                     (stoney)*ishi_2r+x_len+bany1) ; 
  249.                     WGB_singleLine( gwork,
  250.                                     (stonex)*ishi_2r-x_len+banx1,
  251.                                     (stoney)*ishi_2r+x_len+bany1, 
  252.                                     (stonex)*ishi_2r+x_len+banx1,
  253.                                     (stoney)*ishi_2r-x_len+bany1) ; 
  254.                     break;
  255.                 }
  256.             
  257.                 switch(ban[ichi]){
  258.                     case BLANK:
  259.                         break;
  260.                     case BLACK:
  261.                         EGB_color( gwork, 0, WHITE_COL) ; 
  262.                         EGB_color( gwork, 2, WHITE_COL) ; 
  263.                         break;
  264.                     case WHITE:
  265.                         EGB_color( gwork, 0, BLACK_COL) ; 
  266.                         EGB_color( gwork, 2, BLACK_COL) ; 
  267.                         break;
  268.                 }
  269.                 if(ban[ichi] != BLANK){
  270.                         if(ex_ban[ichi] >= 100){
  271.                             s[0] = '0' + ex_ban[ichi]/100;
  272.                             s[1] = '0' + (ex_ban[ichi]%100)/10;
  273.                             s[2] = '0' + (ex_ban[ichi]%10);
  274.                             s[3] = '\0';
  275.                             gprint(s, (stonex)*ishi_2r+banx1-12,
  276.                                       (stoney)*ishi_2r+bany1+8);
  277.                         }else if(ex_ban[ichi] >= 10){
  278.                             s[0] = '0' + ex_ban[ichi]/10;
  279.                             s[1] = '0' + (ex_ban[ichi]%10);
  280.                             s[2] = '\0';
  281.                             gprint(s, (stonex)*ishi_2r+banx1-8,
  282.                                       (stoney)*ishi_2r+bany1+8);
  283.                         }else if(ex_ban[ichi] >= 1){
  284.                             s[0] = '0' + (ex_ban[ichi]%10);
  285.                             s[1] = '\0';
  286.                             gprint(s, (stonex)*ishi_2r+banx1-4,
  287.                                       (stoney)*ishi_2r+bany1+8);
  288.                         }
  289.                 }
  290.             }
  291.         
  292.         save_ban[stonex + stoney*(bansize+1)]    = ban[ichi];
  293.         save_ex_ban[stonex + stoney*(bansize+1)] = ex_ban[ichi];
  294.         
  295.         }
  296.     }
  297.  
  298.     MG_mosDisp( 3 ) ;        /* マウスを表示する */
  299.  
  300.     return 0;
  301. }
  302.  
  303. int disp_te_clear( int stonex, int stoney)
  304. {
  305.  
  306.     EGB_color( gwork, 0, ban_color ) ; 
  307.     EGB_color( gwork, 2, ban_color ) ; 
  308.     WGB_box( gwork, 
  309.             (stonex)*ishi_2r+banx1-ishi_r, 
  310.             (stoney)*ishi_2r+bany1-ishi_r, 
  311.             (stonex)*ishi_2r+banx1+ishi_r, 
  312.             (stoney)*ishi_2r+bany1+ishi_r); 
  313.             /* [46] 四角を描く */
  314.  
  315.     EGB_color( gwork, 0, line_color ) ; 
  316.     EGB_color( gwork, 2, line_color ) ; 
  317.     if(stonex == 1){
  318.         if(stoney == 1){
  319.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1,
  320.                             (stoney)*ishi_2r+bany1, 
  321.                             (stonex)*ishi_2r+banx1,
  322.                             (stoney)*ishi_2r+bany1+ishi_r);
  323.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1,
  324.                             (stoney)*ishi_2r+bany1, 
  325.                             (stonex)*ishi_2r+banx1+ishi_r,
  326.                             (stoney)*ishi_2r+bany1);
  327.         }else if(stoney == bansize){
  328.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1,
  329.                             (stoney)*ishi_2r+bany1-ishi_r, 
  330.                             (stonex)*ishi_2r+banx1,
  331.                             (stoney)*ishi_2r+bany1);
  332.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1,
  333.                             (stoney)*ishi_2r+bany1, 
  334.                             (stonex)*ishi_2r+banx1+ishi_r,
  335.                             (stoney)*ishi_2r+bany1);
  336.         }else{
  337.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1,
  338.                             (stoney)*ishi_2r+bany1-ishi_r, 
  339.                             (stonex)*ishi_2r+banx1,
  340.                             (stoney)*ishi_2r+bany1+ishi_r);
  341.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1,
  342.                             (stoney)*ishi_2r+bany1, 
  343.                             (stonex)*ishi_2r+banx1+ishi_r,
  344.                             (stoney)*ishi_2r+bany1);
  345.         }
  346.     }else if(stonex == bansize){
  347.         if(stoney == 1){
  348.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1,
  349.                             (stoney)*ishi_2r+bany1, 
  350.                             (stonex)*ishi_2r+banx1,
  351.                             (stoney)*ishi_2r+bany1+ishi_r);
  352.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1-ishi_r,
  353.                             (stoney)*ishi_2r+bany1, 
  354.                             (stonex)*ishi_2r+banx1,
  355.                             (stoney)*ishi_2r+bany1);
  356.         }else if(stoney == bansize){
  357.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1,
  358.                             (stoney)*ishi_2r+bany1-ishi_r, 
  359.                             (stonex)*ishi_2r+banx1,
  360.                             (stoney)*ishi_2r+bany1);
  361.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1-ishi_r,
  362.                             (stoney)*ishi_2r+bany1, 
  363.                             (stonex)*ishi_2r+banx1,
  364.                             (stoney)*ishi_2r+bany1);
  365.         }else{
  366.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1,
  367.                             (stoney)*ishi_2r+bany1-ishi_r, 
  368.                             (stonex)*ishi_2r+banx1,
  369.                             (stoney)*ishi_2r+bany1+ishi_r);
  370.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1-ishi_r,
  371.                             (stoney)*ishi_2r+bany1, 
  372.                             (stonex)*ishi_2r+banx1,
  373.                             (stoney)*ishi_2r+bany1);
  374.         }
  375.     }else{
  376.         if(stoney == 1){
  377.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1,
  378.                             (stoney)*ishi_2r+bany1, 
  379.                             (stonex)*ishi_2r+banx1,
  380.                             (stoney)*ishi_2r+bany1+ishi_r);
  381.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1-ishi_r,
  382.                             (stoney)*ishi_2r+bany1, 
  383.                             (stonex)*ishi_2r+banx1+ishi_r,
  384.                             (stoney)*ishi_2r+bany1);
  385.         }else if(stoney == bansize){
  386.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1,
  387.                             (stoney)*ishi_2r+bany1-ishi_r, 
  388.                             (stonex)*ishi_2r+banx1,
  389.                             (stoney)*ishi_2r+bany1);
  390.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1-ishi_r,
  391.                             (stoney)*ishi_2r+bany1, 
  392.                             (stonex)*ishi_2r+banx1+ishi_r,
  393.                             (stoney)*ishi_2r+bany1);
  394.         }else{
  395.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1,
  396.                             (stoney)*ishi_2r+bany1-ishi_r, 
  397.                             (stonex)*ishi_2r+banx1,
  398.                             (stoney)*ishi_2r+bany1+ishi_r);
  399.             WGB_singleLine( gwork, (stonex)*ishi_2r+banx1-ishi_r,
  400.                             (stoney)*ishi_2r+bany1, 
  401.                             (stonex)*ishi_2r+banx1+ishi_r,
  402.                             (stoney)*ishi_2r+bany1);
  403.         }
  404.     }
  405.     
  406.     if( type == NORMAL && bansize == 19){
  407.         switch(stonex){
  408.         case 4: case 10: case 16:
  409.             switch(stoney){
  410.             case 4: case 10: case 16:
  411.                 WORD(para + 0) = (stonex)*ishi_2r+banx1;
  412.                 WORD(para + 2) = (stoney)*ishi_2r+bany1;
  413.                 WORD(para + 4) = 2;
  414.                 WGB_circle( gwork, para ) ;  /* その位置に点を描く */
  415.                 break;
  416.             default:
  417.                 break;
  418.             }
  419.             break;
  420.         default:
  421.             break;
  422.         }
  423.     }
  424.  
  425.     return 0;
  426.  
  427. }
  428.  
  429. int disp_chk(int x, int y)
  430. {
  431. int ichi, stonex, stoney;
  432.     
  433.     if(banx1 < x && x < banx2 && bany1 < y && y < bany2){
  434.         /* 入力の時は盤の端を対象から外す */
  435.         if(banx1+ishi_r < x && x < banx2-ishi_r
  436.             && bany1+ishi_r < y && y < bany2-ishi_r){
  437.             stonex = ((x-(banx1+ishi_r)) / ishi_2r);
  438.             stoney = ((y-(bany1+ishi_r)) / ishi_2r);
  439.             ichi=henkan_disp_out( stonex+1, stoney+1);
  440.             return ichi;
  441.         }else{
  442.             return -2;
  443.         }
  444.     }else{
  445.         return -1;
  446.     }
  447. }
  448.  
  449. int disp_getbansize(int *x, int *y)
  450. {
  451. BAN_TYPE *ban_type;
  452.  
  453.     ban_type = title_bantype_read();
  454.     *x = *y = (ban_type->size + 1) * ISHI_R * 2;
  455.  
  456.     return 0;
  457.  
  458. }
  459.  
  460. /* p 文字列 x 初期座標 y 初期座標 */
  461. int gprint( char *p, int x, int y)
  462. {
  463. int i;
  464. char dsp[80];
  465.  
  466.     WORD(dsp+0) = x;
  467.     WORD(dsp+2) = y;
  468.     for(i=0;i<80;i++){
  469.         dsp[i+6] = (char)(BYTE(p+i));
  470.         if(dsp[i+6] == (char)0 ){
  471.             break;
  472.         }
  473.     }
  474.     WORD(dsp+4) = i;
  475.     EGB_writeMode(gwork, 0);
  476.     WGB_sjisString(gwork, dsp);
  477.     return i;
  478.     
  479. }
  480.  
  481. int gcircle(int x, int y, int r)
  482. {
  483.  
  484.     WORD(para + 0) = x;
  485.     WORD(para + 2) = y;
  486.     WORD(para + 4) = r;
  487.     WGB_circle( gwork, para ) ;/* その位置に点を描く */
  488.  
  489.     return 0;
  490.     
  491. }
  492.